package lxx.springbootdemo.swaggerdemo;


import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@RestController
@Slf4j
public class swaggerdemo {


    @GetMapping("/hello/{inString}")
    @ApiOperation("hello方法请求")
    @ApiImplicitParam(name = "inString", value = "你的入参", required = true, paramType = "path")
    public String hello(@PathVariable(name = "inString") String str1) {

        log.info("hello方法info日志 =>{}",str1);
        log.debug("hello方法debug日志 =>{}",str1);
        return "你好" + str1;
    }

    @PostMapping("/post")
    @ApiOperation(value = "添加用户")
    public String postUser(@RequestBody user user1) {

        String userId = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + UUID.randomUUID().toString().substring(0, 8);

        UserRespone userRespone = new UserRespone();
        userRespone.setUserId(userId);
        log.info("user =>{}",user1.toString());
        String s = JSON.toJSONString(userRespone);
        return s;
    }

    @PostMapping("/post1")
    @ApiOperation(value = "添加用户1")
    public UserRespone postUser1(@RequestBody user user1) {

        String userId = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + UUID.randomUUID().toString().substring(0, 8);

        UserRespone userRespone = new UserRespone();
        userRespone.setUserId(userId);
        log.info("user =>{}",user1.toString());
        return userRespone;
    }

}
